package com.sky.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sky.result.Result;
import com.sky.result.TableDataInfo;

import java.util.List;

/*所有 Controller 需继承改类*/
public class BaseController {

    public Result success(){
        return Result.success();
    }

    public Result error(){
        return Result.error();
    }

    public Result success(String msg){
        return Result.success(msg);
    }

    public Result success(Object data){
        return Result.success(data);
    }

    public Result error(String msg){
        return Result.error(msg);
    }

    public Result toResult(int rows){
        return rows > 0 ? success() : error();
    }

    public Result toResult(boolean result){
        return result ? success() : error();
    }

    public TableDataInfo getTableInfo(List<?> list){
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(200);
        tableDataInfo.setData(list);
        tableDataInfo.setMsg("查询成功");
        tableDataInfo.setTotal(new PageInfo<Object>(list).getTotal());
        return tableDataInfo;
    }
}
